Editor.Shapes.Resource = function (u, i) {
	if (i == undefined) {
		i = this;
	}
	Editor.Shape.call(this, i, u);

	this.element = new Editor.Models.Element();
	this.element.init();

	this.deckEdit = new Editor.Decks.Edit();
	this.deckEdit.init(this);
};

Editor.Util.inherits(Editor.Shapes.Resource, Editor.Shape);

Editor.Shapes.Resource.prototype.draw = function () {
	Editor.Shapes.Resource.superClass_.draw.call(this);
	this.deckEdit.draw();
	this.deckEdit.redraw();
}

Editor.Shapes.Resource.prototype._remove = function () {
	Editor.Shapes.Resource.superClass_._remove.call(this);
	this.deckEdit.remove();
}

Editor.Shapes.Resource.prototype.remove = function () {
	Editor.Shapes.Resource.superClass_.remove.call(this);
	this.deckEdit.remove();
}

Editor.Shapes.Resource.prototype.toFront = function () {
	Editor.Shapes.Resource.superClass_.toFront.call(this);
	this.deckEdit.toFront();
}

Editor.Shapes.Resource.prototype.translate = function (dx, dy) {
	Editor.Shapes.Resource.superClass_._translate.call(this, dx, dy);
	this.deckEdit.translate(dx, dy);
}

Editor.Shapes.Resource.prototype._translate = function (dx, dy) {
	Editor.Shapes.Resource.superClass_._translate.call(this, dx, dy);
	this.deckEdit.translate(dx, dy);
}

Editor.Shapes.Resource.prototype._resize = function (dw, dh) {
	Editor.Shapes.Resource.superClass_._resize.call(this, dw, dh);
	this.deckEdit.redraw();
}

Editor.Shapes.Resource.prototype.resize = function (dw, dh) {
	Editor.Shapes.Resource.superClass_.resize.call(this, dw, dh);
	this.deckEdit.redraw();
}

Editor.Shapes.Resource.prototype.showEdit = function () {
	Editor.Keys.unbind();
	Editor.STATE.SHAPETOUPDATE = this.impl;
	$('#name').val(this.element.getName());
	$('#namespacePrefix').val(this.element.getNamespace().getPrefix());
	$('#namespaceUri').val(this.element.getNamespace().getUri());
	$('#dialogAddResource').jqm({
		overlay: 40,
		modal: true
	}).jqmShow();
}

// set 
Editor.Shapes.Resource.prototype.setNamespace = function (n) {
	this.element.setNamespace(n);
}

Editor.Shapes.Resource.prototype.setName = function (n) {
	this.element.setName(n);
}

// get
Editor.Shapes.Resource.prototype.toObject = function () {
	return {
		'element': this.element.toObject(),
		'shape': Editor.Shapes.Resource.superClass_.toObject.call(this)
	}
}

Editor.Shapes.Resource.prototype.toString = function () {
	return this.impl.getTypeClass() + 'X' + this.impl.getUuid();
}

Editor.Shapes.Resource.prototype.getInfo = function () {
	var name = this.element.getName();
	var prefix = this.element.getNamespace().getPrefix();
	var uri = this.element.getNamespace().getUri();
	var str = '';
	if (Editor.CONFIG.DEBUG) {
		var str = 'Resource:\n';
	}
	str += name + '\n';
	if (prefix != '' && uri != '') {
		str += prefix + ' = ' + uri;
	} else {
		str += 'no namespace';
	}
	if (Editor.CONFIG.DEBUG) {
		str += '\n( x:' + this.impl.getX();
		str += ' ; y:' + this.impl.getY();
		str += ' ; w:' + this.impl.getWidth();
		str += ' ; h:' + this.impl.getHeight() + ' )';
		str += '\nuuid: ' + this.impl.getUuid();
	}
	return str;
}

Editor.Shapes.Resource.prototype.getFigure = function () {
	return Editor.STATE.CANVAS.rect(this.getX(), this.getY(), this.getWidth(), this.getHeight(), Editor.CONFIG.RESOURCE_SHAPE_ROUNDED).
	attr(Editor.CONFIG.RESOURCE_SHAPE_ATTR);
}

Editor.Shapes.Resource.prototype.getShapeAttr = function () {
	return Editor.CONFIG.RESOURCE_SHAPE_ATTR;
}

Editor.Shapes.Resource.prototype.getTypeClass = function () {
	return "resource";
}

Editor.Shapes.Resource.prototype.getDeckEdit = function () {
	return this.deckEdit;
}

Editor.Shapes.Resource.prototype.getNamespace = function () {
	return this.element.getNamespace();
}

Editor.Shapes.Resource.prototype.getName = function () {
	return this.element.getName();
}

Editor.Shapes.Resource.prototype.getText = function () {
	var t = this.element.getNamespace().getPrefix();
	if (t == '') {
		t = '<' + this.element.getName() + '>';
	} else {
		t = this.element.getNamespace().getPrefix() + ':' + this.element.getName();
	}
	return t;
}

Editor.Shapes.Resource.prototype.getTextAttr = function () {
	return Editor.CONFIG.SHAPE_ATTR_TEXT;
}

// event
Editor.Shapes.Resource.prototype.mouseover = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.Resource.superClass_.mouseover.call(this);
		this.deckEdit.mouseover();
	}
}

Editor.Shapes.Resource.prototype.mouseout = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.Resource.superClass_.mouseout.call(this);
		this.deckEdit.mouseout();
	}
}

Editor.Shapes.Resource.prototype.mousedown = function (e) {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.Resource.superClass_.mousedown.call(this, e);
	}
}

Editor.Shapes.Resource.prototype.onmouseup = function () {
	Editor.Shapes.Resource.superClass_.onmouseup.call(this);
}

Editor.Shapes.Resource.prototype.click = function () {
	if (!Editor.Util.isDragging()) {
		Editor.Shapes.Resource.superClass_.click.call(this);
		this.deckEdit.toFront();
	}
}
